<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;

class GrowingCoffeeController extends Controller
{
    public function exchange()
    {
        $user = Auth::user();
        $growingCoffee = $user->growing_coffee;
        if ($growingCoffee >= 1) {
            $user->growing_coffee = 0;
            $user->save();
            //TODO 给用户添加一张成长咖啡券

            return response()->json(['code' => 1, 'message' => '提取成功，成长咖啡已经入库']);
        } else {
            return response()->json(['code' => 1001, 'message' => '成长咖啡不足一杯，无法提取。'], 400);
        }
    }
}
